package com.luotianacg.mode.observerPattern.realizeBySelf;

/**
 * @Author: luotian
 * @Date: 2023/4/9 23:23
 */
public class CurrentConditionsDisplay implements Observer,DisplayElement{
    private float temperature;
    private float humidity;
    private Subject weatherData;
    public CurrentConditionsDisplay(Subject weatherData)
    {
        this.weatherData=weatherData;
        //注册这个观察者
        weatherData.registerObservers(this);
    }
    @Override
    public void display() {
        System.out.println("Current conditions: "+temperature+"F degrees and"+humidity+"%humidity");
    }

    @Override
    public void update(float temp, float humidity, float pressure) {
        this.temperature=temp;
        this.humidity=humidity;
        display();
    }
}
